﻿#-*- coding:utf-8 -*-

import requests
import re
import pymysql


#sql = "select * from images" 
#cur.execute(sql)
#results = cur.fetchall()    #获取查询的所有记录

def getImagesList(page = 1):
	html = requests.get('http://www.doutula.com/photo/list/?page=%d' % (page)).text
	
	pattern = r'data-original="(.*?)".*?alt="(.*?)"'
	reg = re.compile(pattern,re.S)  
	items = re.findall(reg,html) 
	
	db= pymysql.connect(host="127.0.0.1",user="root",  
		password="root",db="db",port=3306,charset='utf8')
	# 使用cursor()方法获取操作游标  
	cur = db.cursor() 

	
	for i in items:
		sql ="insert into images(name,url) values('%s','%s')" % (i[1],i[0])
		cur.execute(sql)
		print('正在保存 %s' % i[1])
		db.commit()
	

for i in range(1,1000):
	getImagesList(i)








